package com.elitetyc.eliteim.client.handler.impl;

import com.elitetyc.eliteim.common.constant.Constants;
import com.elitetyc.eliteim.common.handler.impl.BaseMsgHandler;
import com.elitetyc.eliteim.common.model.impl.U2UMsg;
import com.elitetyc.eliteim.common.proto.RequestProto;
import com.elitetyc.eliteim.common.util.MsgUtil;
import io.netty.channel.ChannelHandlerContext;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

/**
 * @author yuanchao.tan
 * @version 1.0
 * @description 用户到用户消息处理
 * @Date 2021/9/18 9:39
 */
@Component
@Slf4j
public class U2UMsgHandlerImpl extends BaseMsgHandler<U2UMsg> {

    @Override
    public boolean support(int type) {
        return type == Constants.RequestType.U2U;
    }

    @Override
    public void handleMsg(ChannelHandlerContext ctx, RequestProto.RequestProtocol source, U2UMsg msg) {
        MsgUtil.echoMsg(buildLogInfo(msg));
    }

    private String buildLogInfo(U2UMsg msg){
        return String.format("用户【%s(%s)】对你说:%s",
                msg.sender.getUserName(),
                msg.sender.getUserId(),
                msg.content);
    }
}
